<template>
  <div class="contest-management-page">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-wrapper">
        <div class="header-left">
          <div class="title-icon">🏆</div>
          <div class="title-content">
            <h1 class="page-title">比赛管理</h1>
            <p class="page-subtitle">创建和管理编程比赛</p>
          </div>
        </div>
        <button @click="createContest" class="header-create-btn">
          <i class="icon">➕</i>
          创建比赛
        </button>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <main class="main-content">
      <div class="container">
        <!-- 搜索区域 -->
        <div class="search-section">
          <div class="search-wrapper">
            <div class="search-inputs">
              <div class="search-item">
                <label class="search-label">
                  <i class="label-icon">🏷️</i>
                  比赛类型
                </label>
                <select v-model="searchForm.type" class="search-select">
                  <option value="">全部类型</option>
                  <option value="ACM/ICPC比赛">ACM/ICPC比赛</option>
                  <option value="OI比赛">OI比赛</option>
                  <option value="IOI比赛">IOI比赛</option>
                  <option value="Ledo 比赛">Ledo 比赛</option>
                  <option value="IOI(Strict)比赛">IOI(Strict)比赛</option>
                </select>
              </div>
              
              <div class="search-item">
                <label class="search-label">
                  <i class="label-icon">📝</i>
                  比赛名称
                </label>
                <input 
                  v-model="searchForm.title" 
                  type="text" 
                  placeholder="搜索比赛名称..."
                  class="search-input"
                />
              </div>
              
              <div class="search-item">
                <label class="search-label">
                  <i class="label-icon">📊</i>
                  状态
                </label>
                <select v-model="searchForm.status" class="search-select">
                  <option value="">全部状态</option>
                  <option value="未开始">未开始</option>
                  <option value="进行中">进行中</option>
                  <option value="已结束">已结束</option>
                </select>
              </div>
            </div>
            
            <div class="search-actions">
              <button @click="searchContests" class="search-btn">
                <i class="icon">🔍</i>
                搜索
              </button>
              <button @click="refreshContests" :disabled="isRefreshing" class="refresh-btn">
                <i class="icon">🔄</i>
                {{ isRefreshing ? '刷新中...' : '刷新' }}
              </button>
            </div>
          </div>
        </div>

        <!-- 比赛卡片列表 -->
        <div class="contests-container">
          <div v-if="contests.length === 0" class="empty-state">
            <div class="empty-icon">📭</div>
            <p class="empty-text">暂无比赛数据</p>
            <button @click="createContest" class="create-first-btn">创建第一个比赛</button>
          </div>

          <div v-else class="contests-grid">
            <div v-for="contest in contests" :key="contest.id" class="contest-card">
              <div class="card-header">
                <div class="contest-type" :class="getTypeClass(contest.type)">
                  {{ contest.type }}
                </div>
                <div class="contest-status" :class="getStatusClass(contest.status || contest.statusDesc)">
                  {{ contest.status || contest.statusDesc || '未知状态' }}
                </div>
              </div>
              
              <div class="card-body">
                <h3 class="contest-title">{{ contest.title || contest.name }}</h3>
                <p class="contest-description">{{ contest.description || '暂无描述' }}</p>
                
                <div class="contest-info">
                  <div class="info-item">
                    <i class="icon">📅</i>
                    <span>{{ formatDate(contest.startTime) }} - {{ formatDate(contest.endTime) }}</span>
                  </div>
                  <div class="info-item">
                    <i class="icon">👥</i>
                    <span>参赛人数: {{ contest.participantCount || contest.registrationCount || 0 }}</span>
                  </div>
                  <div class="info-item">
                    <i class="icon">📝</i>
                    <span>题目数量: {{ contest.questionCount || contest.questions?.length || 0 }}</span>
                  </div>
                  <div class="info-item" v-if="contest.maxParticipants">
                    <i class="icon">🎯</i>
                    <span>人数限制: {{ contest.maxParticipants }}</span>
                  </div>
                </div>
              </div>
              
              <div class="card-footer">
                <button @click="viewContest(contest)" class="action-btn view-btn">
                  <i class="icon">👁️</i>
                  查看
                </button>
                <button @click="editContest(contest)" class="action-btn edit-btn">
                  <i class="icon">✏️</i>
                  编辑
                </button>
                <button @click="deleteContestItem(contest)" class="action-btn delete-btn">
                  <i class="icon">🗑️</i>
                  删除
                </button>
              </div>
            </div>
          </div>
        </div>

        <!-- 分页 -->
        <div class="pagination-container" v-if="totalCount > 0">
          <div class="pagination">
            <span class="page-info">(共 {{ totalCount }} 条)</span>
            <button 
              @click="goToPage(currentPage - 1)"
              :disabled="currentPage <= 1"
              class="page-btn"
            >
              上一页
            </button>
            <span class="current-page">{{ currentPage }} / {{ totalPages }}</span>
            <button 
              @click="goToPage(currentPage + 1)"
              :disabled="currentPage >= totalPages"
              class="page-btn"
            >
              下一页
            </button>
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import logger from '../utils/logger.js'
import { getContestList, deleteContest } from '@/api/contest'

export default {
  name: 'ContestManagement',
  data() {
    return {
      searchForm: {
        type: '',
        title: '',
        status: ''
      },
      contests: [],
      isRefreshing: false,
      currentPage: 1,
      pageSize: 10,
      totalCount: 0,
      totalPages: 1
    }
  },
  
  mounted() {
    logger.log('🏆 [ContestManagement] 比赛管理页面已加载')
    this.loadContests()
  },
  
  methods: {
    // 获取当前用户ID（从JWT令牌中解析，保持19位精度）
    getCurrentUserId() {
      try {
        const token = localStorage.getItem('token')
        if (token) {
          try {
            const tokenParts = token.split('.')
            if (tokenParts.length === 3) {
              const payloadBase64 = tokenParts[1]
              const payloadStr = atob(payloadBase64)
              logger.log('🔍 [ContestManagement] JWT payload字符串:', payloadStr)
              
              // 使用正则表达式提取ID，保持字符串格式
              const idMatch = payloadStr.match(/"id":(\d+)/)
              if (idMatch && idMatch[1]) {
                const userId = idMatch[1] // 保持字符串格式
                logger.log('👤 [ContestManagement] 从JWT令牌获取用户ID (字符串格式):', userId)
                logger.log('👤 [ContestManagement] 用户ID长度:', userId.length, '位')
                return userId
              }
            }
          } catch (tokenError) {
            logger.warn('⚠️ [ContestManagement] JWT令牌解析失败:', tokenError)
          }
        }
        
        // 备选方案：从localStorage获取用户信息
        const userInfoStr = localStorage.getItem('userInfo')
        if (userInfoStr) {
          const userInfo = JSON.parse(userInfoStr)
          const userId = String(userInfo.id || '')
          logger.log('👤 [ContestManagement] 从localStorage获取用户ID:', userId)
          return userId
        }
      } catch (error) {
        logger.error('❌ [ContestManagement] 解析用户信息失败:', error)
      }
      
      logger.warn('⚠️ [ContestManagement] 无法获取用户ID')
      return null
    },
    
    // 加载比赛列表
    async loadContests() {
      logger.log('📋 [ContestManagement] 加载比赛列表')
      
      try {
        // 获取当前用户ID
        const userId = this.getCurrentUserId()
        if (!userId) {
          logger.error('❌ [ContestManagement] 无法获取用户ID')
          if (this.$message && this.$message.error) {
            this.$message.error('获取用户信息失败，请重新登录')
          } else {
            alert('❌ 获取用户信息失败，请重新登录')
          }
          return
        }
        
        // 构建查询参数
        const params = {
          page: this.currentPage,
          size: this.pageSize,
          createUserId: userId  // 添加用户ID参数（字符串格式，后端会转为long类型）
        }
        
        // 添加搜索条件
        if (this.searchForm.type) {
          params.type = this.searchForm.type
        }
        if (this.searchForm.title) {
          params.title = this.searchForm.title
        }
        if (this.searchForm.status) {
          params.status = this.searchForm.status
        }
        
        logger.log('📋 [ContestManagement] 请求参数:', params)
        logger.log('👤 [ContestManagement] 用户ID:', params.createUserId, '类型:', typeof params.createUserId)
        
        // 调用API获取比赛列表
        const response = await getContestList(params)
        
        logger.log('✅ [ContestManagement] API响应:', response)
        
        // 检查业务状态码
        if (response && response.code === 0 && response.data) {
          logger.log('✅ [ContestManagement] 比赛列表获取成功（code = 0）')
          
          // 处理响应数据
          if (response.data.records && Array.isArray(response.data.records)) {
            this.contests = response.data.records
            this.totalCount = response.data.total || 0
            this.totalPages = response.data.pages || Math.ceil(this.totalCount / this.pageSize) || 1
            this.currentPage = response.data.current || this.currentPage
          } else if (Array.isArray(response.data)) {
            // 如果直接返回数组
            this.contests = response.data
            this.totalCount = this.contests.length
            this.totalPages = Math.ceil(this.totalCount / this.pageSize) || 1
          } else {
            this.contests = []
            this.totalCount = 0
            this.totalPages = 1
          }
          
          logger.log('📊 [ContestManagement] 比赛数量:', this.contests.length)
          logger.log('📄 [ContestManagement] 当前页:', this.currentPage)
          logger.log('📄 [ContestManagement] 总页数:', this.totalPages)
        } else {
          logger.warn('⚠️ [ContestManagement] 获取比赛列表失败:', response?.message)
          this.contests = []
          this.totalCount = 0
          this.totalPages = 1
        }
        
      } catch (error) {
        logger.error('❌ [ContestManagement] 加载比赛列表失败:', error)
        this.contests = []
        this.totalCount = 0
        this.totalPages = 1
      }
      
      logger.log('✅ [ContestManagement] 比赛列表加载完成:', this.contests)
    },
    
    // 搜索比赛
    searchContests() {
      logger.log('🔍 [ContestManagement] 搜索比赛:', this.searchForm)
      // 搜索时重置到第一页
      this.currentPage = 1
      this.loadContests()
    },
    
    // 刷新比赛列表
    async refreshContests() {
      logger.log('🔄 [ContestManagement] 刷新比赛列表')
      this.isRefreshing = true
      
      try {
        // 重置到第一页并加载
        this.currentPage = 1
        await this.loadContests()
        
        // 移除成功提示，直接刷新列表以改善用户体验
        // if (this.$message && this.$message.success) {
        //   this.$message.success('刷新成功')
        // } else {
        //   alert('✅ 刷新成功')
        // }
      } catch (error) {
        logger.error('❌ [ContestManagement] 刷新失败:', error)
        
        if (this.$message && this.$message.error) {
          this.$message.error('刷新失败')
        } else {
          alert('❌ 刷新失败')
        }
      } finally {
        this.isRefreshing = false
      }
    },
    
    // 创建比赛
    createContest() {
      logger.log('➕ [ContestManagement] 创建比赛')
      this.$router.push('/contest-create')
    },
    
    // 查看比赛
    viewContest(contest) {
      logger.log('👁️ [ContestManagement] 查看比赛:', contest)
      logger.log('🔗 [ContestManagement] 跳转到比赛详情页面，ID:', contest.id)
      
      // 跳转到比赛详情页面，添加来源标识
      this.$router.push({
        name: 'ContestDetail',
        params: { id: contest.id },
        query: { from: 'management' }  // 标识从比赛管理页面进入
      })
    },
    
    // 编辑比赛
    editContest(contest) {
      logger.log('✏️ [ContestManagement] 编辑比赛:', contest)
      this.$router.push({
        name: 'ContestEdit',
        params: { id: contest.id }
      })
    },
    
    // 删除比赛
    async deleteContestItem(contest) {
      logger.log('🗑️ [ContestManagement] 删除比赛:', contest)
      
      const contestTitle = contest.title || contest.name || '该比赛'
      const confirmed = confirm(`确定要删除比赛"${contestTitle}"吗？`)
      if (!confirmed) {
        logger.log('❌ [ContestManagement] 用户取消删除')
        return
      }
      
      try {
        logger.log('🔥 [ContestManagement] 执行删除操作，比赛ID:', contest.id)
        
        // 调用删除API
        const response = await deleteContest(contest.id)
        
        logger.log('✅ [ContestManagement] API响应:', response)
        
        // 检查业务状态码
        if (response && response.code === 0) {
          logger.log('✅ [ContestManagement] 比赛删除成功（code = 0）')
          
          // 移除成功提示，直接刷新列表以改善用户体验
          // const successMsg = response.message || '删除成功'
          // if (this.$message && this.$message.success) {
          //   this.$message.success(successMsg)
          // } else {
          //   alert('✅ ' + successMsg)
          // }
          
          // 重新加载比赛列表
          await this.loadContests()
        } else {
          logger.error('❌ [ContestManagement] 删除失败，业务状态码异常')
          logger.error('❌ [ContestManagement] code:', response?.code)
          logger.error('❌ [ContestManagement] message:', response?.message)
          
          const errorMsg = response?.message || '删除失败'
          if (this.$message && this.$message.error) {
            this.$message.error(errorMsg)
          } else {
            alert('❌ ' + errorMsg)
          }
        }
      } catch (error) {
        logger.error('❌ [ContestManagement] 删除失败:', error)
        
        let errorMsg = '删除失败，请重试'
        if (error.response?.data?.message) {
          errorMsg = error.response.data.message
        } else if (error.message) {
          errorMsg = error.message
        }
        
        if (this.$message && this.$message.error) {
          this.$message.error(errorMsg)
        } else {
          alert('❌ ' + errorMsg)
        }
      }
    },
    
    // 格式化日期
    formatDate(dateString) {
      if (!dateString) return '-'
      
      try {
        const date = new Date(dateString)
        const year = date.getFullYear()
        const month = String(date.getMonth() + 1).padStart(2, '0')
        const day = String(date.getDate()).padStart(2, '0')
        const hours = String(date.getHours()).padStart(2, '0')
        const minutes = String(date.getMinutes()).padStart(2, '0')
        
        return `${year}-${month}-${day} ${hours}:${minutes}`
      } catch (error) {
        logger.error('❌ [ContestManagement] 日期格式化失败:', error)
        return dateString
      }
    },
    
    // 获取比赛类型样式类名
    getTypeClass(type) {
      const typeMap = {
        'ACM/ICPC比赛': 'type-acm',
        'OI比赛': 'type-oi',
        'IOI比赛': 'type-ioi',
        'Ledo 比赛': 'type-ledo',
        'IOI(Strict)比赛': 'type-ioi-strict'
      }
      return typeMap[type] || ''
    },
    
    // 获取状态样式类名
    getStatusClass(status) {
      const statusMap = {
        '未开始': 'status-pending',
        '进行中': 'status-active',
        '已结束': 'status-finished'
      }
      return statusMap[status] || ''
    },
    
    // 分页跳转
    goToPage(page) {
      if (page < 1 || page > this.totalPages) return
      
      this.currentPage = page
      logger.log('📄 [ContestManagement] 跳转到第', page, '页')
      this.loadContests()
    }
  }
}
</script>

<style scoped>
.contest-management-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 30px 20px;
}

/* 页面头部 */
.page-header {
  margin-bottom: 30px;
  animation: fadeInDown 0.6s ease;
}

.header-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.95));
  padding: 30px 40px;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.title-icon {
  font-size: 48px;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.title-content {
  display: flex;
  flex-direction: column;
}

.page-title {
  font-size: 2.2em;
  margin: 0;
  color: #2c3e50;
  font-weight: 700;
  background: linear-gradient(135deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-subtitle {
  font-size: 1em;
  color: #7f8c8d;
  margin: 5px 0 0 0;
}

.header-create-btn {
  padding: 12px 28px;
  background: linear-gradient(135deg, #4CAF50, #45a049);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.header-create-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.header-create-btn .icon {
  font-size: 18px;
}

/* 主要内容 */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
}

.container {
  background: rgba(255, 255, 255, 0.98);
  border-radius: 20px;
  padding: 35px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  animation: fadeInUp 0.6s ease;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 搜索区域 */
.search-section {
  margin-bottom: 35px;
  padding: 25px;
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  border-radius: 15px;
  border: 2px solid rgba(102, 126, 234, 0.1);
}

.search-wrapper {
  display: flex;
  gap: 20px;
  align-items: flex-end;
}

.search-inputs {
  display: flex;
  gap: 15px;
  flex: 1;
  flex-wrap: wrap;
}

.search-item {
  display: flex;
  flex-direction: column;
  min-width: 200px;
  flex: 1;
}

.search-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #555;
  margin-bottom: 8px;
  font-weight: 600;
}

.label-icon {
  font-size: 16px;
}

.search-input,
.search-select {
  padding: 11px 15px;
  border: 2px solid #dee2e6;
  border-radius: 10px;
  font-size: 14px;
  transition: all 0.3s ease;
  background: white;
}

.search-input:focus,
.search-select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
  transform: translateY(-1px);
}

.search-input::placeholder {
  color: #adb5bd;
}

.search-actions {
  display: flex;
  gap: 10px;
}

.search-btn,
.refresh-btn {
  padding: 11px 24px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.3s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-btn {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.search-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.refresh-btn {
  background: white;
  color: #667eea;
  border: 2px solid #667eea;
}

.refresh-btn:hover:not(:disabled) {
  background: #667eea;
  color: white;
  transform: translateY(-2px);
}

.refresh-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 比赛卡片 */
.contests-container {
  min-height: 400px;
}

.empty-state {
  text-align: center;
  padding: 100px 20px;
  animation: fadeIn 0.8s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.empty-icon {
  font-size: 100px;
  margin-bottom: 25px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

.empty-text {
  font-size: 20px;
  color: #6c757d;
  margin-bottom: 35px;
  font-weight: 500;
}

.create-first-btn {
  padding: 14px 35px;
  background: linear-gradient(135deg, #4CAF50, #45a049);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  transition: all 0.3s ease;
  box-shadow: 0 5px 20px rgba(76, 175, 80, 0.3);
}

.create-first-btn:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 25px rgba(76, 175, 80, 0.4);
}

.contests-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 25px;
  animation: fadeIn 0.6s ease;
}

.contest-card {
  background: white;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid transparent;
  position: relative;
}

.contest-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #667eea, #764ba2);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.contest-card:hover::before {
  opacity: 1;
}

.contest-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 12px 35px rgba(102, 126, 234, 0.2);
  border-color: rgba(102, 126, 234, 0.3);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.contest-type {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.type-acm {
  background: #e3f2fd;
  color: #1976d2;
}

.type-oi {
  background: #f3e5f5;
  color: #7b1fa2;
}

.type-ioi {
  background: #e8f5e9;
  color: #388e3c;
}

.type-ledo {
  background: #fff3e0;
  color: #f57c00;
}

.type-ioi-strict {
  background: #fce4ec;
  color: #c2185b;
}

.contest-status {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.status-pending {
  background: #fff3e0;
  color: #f57c00;
}

.status-active {
  background: #e8f5e9;
  color: #388e3c;
}

.status-finished {
  background: #e0e0e0;
  color: #616161;
}

.card-body {
  padding: 24px;
}

.contest-title {
  font-size: 19px;
  font-weight: 700;
  color: #2c3e50;
  margin: 0 0 12px 0;
  line-height: 1.4;
}

.contest-description {
  font-size: 14px;
  color: #6c757d;
  margin: 0 0 18px 0;
  line-height: 1.6;
  max-height: 3.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.contest-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8f9fa;
  padding: 15px;
  border-radius: 10px;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #495057;
  font-weight: 500;
}

.info-item .icon {
  font-size: 18px;
  min-width: 20px;
  text-align: center;
}

.card-footer {
  display: flex;
  justify-content: space-around;
  padding: 18px 24px;
  background: linear-gradient(135deg, #fafbfc, #f8f9fa);
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  gap: 10px;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex: 1;
  min-width: 80px;
}

.action-btn .icon {
  font-size: 16px;
}

.view-btn {
  background: linear-gradient(135deg, #e3f2fd, #bbdefb);
  color: #1976d2;
  border: 1px solid #90caf9;
}

.view-btn:hover {
  background: linear-gradient(135deg, #1976d2, #1565c0);
  color: white;
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(25, 118, 210, 0.3);
}

.edit-btn {
  background: linear-gradient(135deg, #fff3e0, #ffe0b2);
  color: #f57c00;
  border: 1px solid #ffb74d;
}

.edit-btn:hover {
  background: linear-gradient(135deg, #f57c00, #e64a19);
  color: white;
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(245, 124, 0, 0.3);
}

.delete-btn {
  background: linear-gradient(135deg, #ffebee, #ffcdd2);
  color: #d32f2f;
  border: 1px solid #ef9a9a;
}

.delete-btn:hover {
  background: linear-gradient(135deg, #d32f2f, #c62828);
  color: white;
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(211, 47, 47, 0.3);
}

/* 分页 */
.pagination-container {
  margin-top: 40px;
  display: flex;
  justify-content: center;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 15px;
  background: white;
  padding: 15px 25px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

.page-info {
  color: #6c757d;
  font-size: 14px;
  font-weight: 500;
}

.page-btn {
  padding: 10px 20px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.3s ease;
  box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}

.page-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #5568d3, #6941a5);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.page-btn:disabled {
  background: #dee2e6;
  color: #adb5bd;
  cursor: not-allowed;
  box-shadow: none;
}

.current-page {
  font-weight: 700;
  color: #2c3e50;
  font-size: 15px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .contest-management-page {
    padding: 15px 10px;
  }
  
  .header-wrapper {
    flex-direction: column;
    gap: 20px;
    padding: 25px;
  }
  
  .header-left {
    flex-direction: column;
    text-align: center;
  }
  
  .title-icon {
    font-size: 40px;
  }
  
  .page-title {
    font-size: 1.8em;
  }
  
  .header-create-btn {
    width: 100%;
    justify-content: center;
  }
  
  .search-wrapper {
    flex-direction: column;
  }
  
  .search-inputs {
    width: 100%;
    flex-direction: column;
  }
  
  .search-item {
    min-width: 100%;
  }
  
  .search-actions {
    width: 100%;
  }
  
  .search-btn,
  .refresh-btn {
    flex: 1;
  }
  
  .contests-grid {
    grid-template-columns: 1fr;
  }
  
  .card-footer {
    flex-direction: column;
    gap: 8px;
  }
  
  .action-btn {
    width: 100%;
  }
}
</style>

